﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="tag.aspx.cs" Inherits="www.pages.tag.tag" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <link href="../../css/lanai-ui.min.css" rel="stylesheet" />
</head>
<body>
    <section class="content no-pad-top">
        <form id="form1" runat="server">
            <div class="box box-widget no-shadow no-radius-childs">
                <div class="box-body">
                    <div class="form-group">
                        <label>标签名称(<span class="text-red">*</span>)</label>
                        <input id="txt_tagname" type="text" class="form-control" placeholder="请输入标签名称" runat="server" />
                    </div>
                    <div class="row">
                        <div class="col-sm-4 col-xs-4">
                            <div class="form-group">
                                <label>类型(<span class="text-red">*</span>)</label>
                                <asp:DropDownList ID="sl_type" runat="server" CssClass="form-control">
                                    <asp:ListItem Text="通用" Value="common" Selected="True"></asp:ListItem>
                                    <asp:ListItem Text="专属" Value="exclusive"></asp:ListItem>
                                </asp:DropDownList>
                            </div>
                        </div>
                        <div class="col-sm-8 col-xs-8">
                            <div class="form-group">
                                <label>描述</label>
                                <input id="txt_tagcomment" type="text" class="form-control" runat="server" />
                            </div>
                        </div>
                    </div>
                    <div id="sl_doc"<%=IsshowDocHtml %> >
                        <asp:Repeater ID="list_docs" runat="server">
                            <HeaderTemplate>
                                <table class="table table-bordered table-striped table-hover text-center">
                                    <thead>
                                        <tr>
                                            <th style="width: 60px">选择</th>
                                            <th>文档名称</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <tr>
                                    <td>
                                        <%#createCheckHtml(Eval("doc_id").ToString(),Eval("tag_id").ToString()) %></td>
                                    <td><%#Eval("doc_name") %></td>
                                </tr>
                            </ItemTemplate>
                            <FooterTemplate>
                                </tbody>
                        </table>
                            </FooterTemplate>
                        </asp:Repeater>
                    </div>
                    <div class="form-group">
                        <label>内容</label>
                        <textarea id="txtText" rows="5" class="form-control" runat="server"></textarea>
                    </div>
                </div>
                <div class="box-footer navbar-fixed-bottom">
                    <a href="#" id="btnsaveTag" class="pull-right btn btn-default btn-flat">保存标签</a>
                </div>
            </div>
            <input type="hidden" id="hid_project" runat="server" value="0" />
            <input type="hidden" id="hid_tagid" runat="server" value="0" />
        </form>
    </section>
    <script src="../../js/jquery.min.js"></script>
    <script src="../../plugins/ckeditor/ckeditor.js"></script>
    <script src="../../plugins/ckfinder/ckfinder.js"></script>
    <script src="../../js/lanai-ui.min.js"></script>
    <script type="text/javascript">
        $(function () {
            var content = CKEDITOR.replace("txtText", { toolbarCanCollapse: true, toolbarStartupExpanded: false, height: 300 });
            CKFinder.setupCKEditor(content, '../../plugins/ckfinder/');

            $("#sl_type").change(function () {
                if ($(this).val() == "exclusive") {
                    $("#sl_doc").css("display", "block");
                }
                else {
                    $("#sl_doc").css("display", "none");
                }
            });


            $("#btnsaveTag").click(function () {
                var that = this;
                var tagid = $("#hid_tagid").val();
                var tagname = $("#txt_tagname").val();
                var tagcomment = $("#txt_tagcomment").val();
                var tagtype = $("#sl_type").val();
                var tagcontent = content.document.getBody().getHtml();
                var docs = [];
                if (tagname == "") {
                    parent.layer.alert("请输入标签名称", { title: '系统提示', icon: 2 });
                    return;
                }
                if (tagtype == "exclusive") {
                    if ($("input[type=checkbox]:checked").length <= 0) {
                        parent.layer.alert("请选择对应文档", { title: '系统提示', icon: 2 });
                        return;
                    }
                    $("input[type=checkbox]:checked").each(function (i, el) {
                        docs.push($(el).data("docid"));
                    })
                }
                parent.doSaveTag(tagid, tagname, tagcomment, tagtype, tagcontent, JSON.stringify(docs));
            })
        });
    </script>
</body>
</html>
